package com.stylefeng.guns.core.util;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 使用org.apache.commons.beanutils进行转换
 */
public class MapUtils {


    public static Object mapToObject(Map<String, Object> map, Class<?> beanClass) throws Exception {
        if (map == null)
            return null;

        Object obj = beanClass.newInstance();

        org.apache.commons.beanutils.BeanUtils.populate(obj, map);

        return obj;
    }

    public static Map<?, ?> objectToMap(Object obj) {
        if(obj == null)
            return null;

        return new org.apache.commons.beanutils.BeanMap(obj);
    }
    public static List< Map> batchObjectToMap(List list)
    {
        List< Map> result=new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            try {
                result.add(objectToMap(list.get(i)));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return result;
    }

}


